package com.acme.controller;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.acme.dao.ClaimDAO;
import com.acme.entity.Claim;

@Transactional
@Controller
@RequestMapping(value = "InsuranceAdjusterClaimApprove")
public class ApproveInsuranceAdjusterController {
	@Autowired
	private ClaimDAO claimDAO;

	@RequestMapping(method = RequestMethod.GET)
	public ModelAndView admin(){
		ModelAndView model = new ModelAndView();
		model.getModelMap().addAttribute("submittedClaims", claimDAO.getClaimsSubmmitted());
		return model;
	}
	@RequestMapping(method = RequestMethod.POST)
	public ModelAndView processClaimStatusChange(@RequestParam(value= "status", required= true) int idclaim, String status){
		Claim claim = claimDAO.getClaimByID(idclaim);
		claim.setStatus("Approved");
		claimDAO.updateClaim(claim);
		ModelAndView model = new ModelAndView();
		model.getModelMap().addAttribute("submittedClaims", claimDAO.getClaimsSubmmitted());
		admin();
		return model;
	}
}
